package com.lsh.oms.provider.service.sign;

import com.alibaba.dubbo.config.annotation.Service;
import com.lsh.base.common.model.CommonResult;
import com.lsh.oms.api.service.sign.ISignOrderRestService;
import com.lsh.oms.core.service.sign.core.SignService;
import com.lsh.oms.core.service.tool.Criteria;
import com.lsh.oms.provider.service.BaseService;

import javax.annotation.Resource;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

/**
 * should be replace by /signs soon
 */
@Path("sign-orders")
@Service(protocol = "rest", timeout = 30000)
public class SignOrderRestServiceImpl extends BaseService implements ISignOrderRestService {

    @Resource
    private SignService signService;

    @GET
    @Produces({MediaType.APPLICATION_JSON})
    @Override
    public CommonResult query(@Context UriInfo uriInfo,
                              @DefaultValue("1") @QueryParam("page") long page,
                              @DefaultValue("20") @QueryParam("page-limit") long limit) {
        return CommonResult.success(signService.query(Criteria.of(uriInfo), page, limit));
    }

    @GET
    @Path("{id}")
    @Produces({MediaType.APPLICATION_JSON})
    @Override
    public CommonResult findById(@Context UriInfo uriInfo,
                                 @PathParam("id") Long id) {
        return CommonResult.success(signService.findById(id, Criteria.of(uriInfo)));
    }
}
